package com.example.dataextraction.datasources;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DynamicDataSourceAspect {
    @Pointcut(value="@annotation(dataSource)")
    public void dataSourcePointCut(MyDataSource dataSource){}
    @Before(value = "dataSourcePointCut(dataSource)")
    public void setDataSource(MyDataSource dataSource){
        DynamicDataSource.set(dataSource.value());
    }
    @After(value = "dataSourcePointCut(dataSource)")
    public void removeDataSource(MyDataSource dataSource){
        DynamicDataSource.remove();
    }
}